Skip to content

Fix out-of-bounds read in BinaryReaderLogging::WriteIndent#2795

Merged
sbc100 merged 1 commit into
WebAssembly:mainfrom
aizu-m:logging-writeindent-overread
Jul 11, 2026
Merged

Fix out-of-bounds read in BinaryReaderLogging::WriteIndent#2795
sbc100 merged 1 commit into
WebAssembly:mainfrom
aizu-m:logging-writeindent-overread

Conversation

@aizu-m

@aizu-m aizu-m commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Found with ASan while feeding fuzz-style modules to wasm-objdump --debug:

==ERROR: AddressSanitizer: global-buffer-overflow
READ of size 144 at 0x... thread T0
    #5 wabt::BinaryReaderLogging::WriteIndent() binary-reader-logging.cc:75
    #6 wabt::BinaryReaderLogging::BeginGenericCustomSection(...)
0x... is located 0 bytes after global variable
  'WriteIndent()::s_indent' ... of size 143

WriteIndent emits the indent from a fixed 142-space buffer in chunks. The loop writes full blocks and shrinks i; the leftover write then passed indent_, the whole width, rather than i. Once the indent grows past the buffer that leftover write runs off the end. WatWriter::WriteIndent uses the same loop but writes the leftover count, so this was the odd one out.

How the indent gets that big: it rises by two on every section Begin. A custom name section whose sub-section size runs past the section end fails after BeginNamesSection, and objdump reads with stop_on_first_error and fail_on_custom_section_error both off, so the matching End callbacks never run and the indent leaks a little per bad section. Enough of them and it passes the buffer during the prepass logging.

Regression test added under test/binary-reader; it overruns without the change and is clean with it.

The remainder write passed indent_ instead of the leftover count i, so once the log indent grew past the static space buffer it read off the end. Use i, matching WatWriter::WriteIndent.
@sbc100 sbc100 merged commit 33328a0 into WebAssembly:main Jul 11, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants